﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Xsl;
using System.Xml;
using System.Text;
using System.Web.Routing;

namespace Skynet.WebSite.Mobile.Menu.WAP
{
    public class defaulthandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var CategoriesMgm = RouteTable.Routes.GetVirtualPath(null, "owlvey-mobile-CategoriesMgmView", new RouteValueDictionary() { });
            
            context.Response.ContentType = "text/vnd.wap.wml";
            context.Response.Charset = "";
            XslCompiledTransform xslt = new XslCompiledTransform();
            XsltArgumentList args = new XsltArgumentList();
            args.AddParam("MgmCategories", "",CategoriesMgm.VirtualPath);

            StringBuilder correo = new StringBuilder();
            XmlWriterSettings sett = new XmlWriterSettings();
            sett.ConformanceLevel = ConformanceLevel.Auto;
            XmlWriter wrcorreo = XmlWriter.Create(correo, sett);


            var path = context.Server.MapPath("default.xslt");
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<wml></wml>");
            xslt.Load(path);
            xslt.Transform(doc, args, wrcorreo);
            wrcorreo.Close();
            context.Response.Write(correo.ToString());           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}